(n)certainties – Columbia – Fall 2008

EM_Spheres along a Curve

This script is generating spheres with certain radius variation along a curve:

Option Explicit
‘If it is working then scripted by Eduardo Mayoral
‘If Not scripted by anyone else

Call Spheres()

Sub Spheres()
 
 ’============================================
 ’  Selecting and Evaluating Path Curve
 ’============================================
 
 Dim crvObject : crvObject = Rhino.GetObject(“Select a Curve”, 4, True, False)
 Dim intSamples : intSamples = Rhino.GetInteger(“Number of Cross Sections”, 50, 5)
 
 Dim crvDomain : crvDomain = Rhino.CurveDomain(crvObject)
 Dim t, n

 Dim arrCrossSections(), CrossSectionPlane
 Dim crvCurvature, crvPoint, crvTangent, crvPerp, crvNormal
 
 n = -1

 For t = crvDomain(0) To crvDomain(1) + 1e-9 Step (crvDomain(1)-crvDomain(0))/intSamples

  Dim dblRadius : dblRadius = random(3,3.5)

  n = n+1
  
  crvCurvature = Rhino.CurveCurvature(crvObject, t)

  If IsNull(crvCurvature) Then
   
   crvPoint = Rhino.EvaluateCurve(crvObject, t)
   crvTangent = Rhino.CurveTangent(crvObject, t)
   crvPerp = Array(0,0,1)
   crvNormal = Rhino.VectorCrossProduct(crvTangent, crvPerp)

  Else
   
   crvPoint = crvCurvature(0)
   crvTangent = crvCurvature(1)
   crvPerp = Rhino.VectorUnitize(crvCurvature(4))
   crvNormal = Rhino.VectorCrossProduct(crvTangent, crvPerp)

  End If
   
  ’============================================
  ’  Drawing Spheres
  ’============================================

  CrossSectionPlane = Rhino.PlaneFromFrame(crvPoint, crvPerp, crvNormal)
  ReDim Preserve arrCrossSections(n)
  arrCrossSections(n) = Rhino.AddSphere(CrossSectionPlane, dblRadius)

 Next
 
 If n < 1 Then Exit Sub
 
End Sub

 ’============================================
 ’  Random Function for the Sphere Radius
 ’============================================

Function random(intLow,intUp)
 
 Randomize
 
 random = (intUp-intLow) * Rnd() + intLow
 
End Function

Leave a Comment

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment